package com.kx.yooli.kx.wechat.mapper.nplm;

import com.kx.yooli.kx.wechat.entity.nplm.NplmRepayPlan;
import com.kx.yooli.kx.wechat.entity.nplm.NplmRepayPlanOffline;
import com.mybatisflex.annotation.UseDataSource;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

public interface NplmRepayPlanMapper extends BaseMapper<NplmRepayPlan> {
    @UseDataSource("ds4")
    default List<NplmRepayPlan> selectPlanListByLoan(String loan){
        return selectListWithRelationsByQuery(QueryWrapper.create()
                .select("LOAN_NO as loanNo,REPAY_STATUS as status,INDEED_TOTAL as IndeedTotal,REPAY_DATE as repayDate")
                .from(NplmRepayPlan.class).where(NplmRepayPlan::getLoanNo).eq(loan).and(NplmRepayPlan::getStatus).eq("1")
                .and("PHASE_NUMBER <> 0")
                .unionAll(
                        QueryWrapper.create()
                        .select("LOAN_NO as loanNo,`STATUS` as status,REPAY_AMOUNT as IndeedTotal,RECORD_TIME as repayDate")
                        .from(NplmRepayPlanOffline.class)
                        .and(NplmRepayPlanOffline::getStatus).eq("1").and(NplmRepayPlanOffline::getLoanNo).eq(loan)
                )
        );
    }


}
